import { _decorator, Component, Node, Vec2, Vec3, v3, clamp01 } from 'cc';
import GlobalPool from '../../../Init/Tools/GlobalPool';
import { BasicEffect } from './BasicEffect';
const { ccclass, property } = _decorator;

@ccclass('BoomArea')
export class BoomArea extends BasicEffect {
    boomTime = 0;
    curTime = 0;
    coundownArea: Node = null;

    init(parent: Node, p: Vec3, s: number, t: number) {
        this.node.parent = parent;
        this.node.setPosition(v3(p.x, p.y + 0.05, p.z));
        this.node.setScale(s, s, s);
        this.boomTime = t;
        this.curTime = 0;
        //
        this.coundownArea = this.node.getChildByName('countdown');
        this.coundownArea.setScale(0, 0, 0);
    }

    update(dt: any): void {
        this.curTime += dt;
        if (this.curTime >= this.boomTime) {
            this.curTime = 0;
            GlobalPool.put(this.node);
        }

        let s = clamp01(this.curTime / this.boomTime);
        s = Math.sin(s * 1.57) * 1.25;
        this.coundownArea.setScale(s, s, 1);
    }
}

